import React, { PureComponent } from 'react'
import { connect } from 'dva';

export interface Props {
  dispatch?: Function,
  children?: React.ReactNode,
  details?: {
    name: string,
    address: string,
    id: string
  },
  onChanges: Function;
}

@connect(({ qrcode_owner = {} }) => ({
  details: qrcode_owner.details || {},
}))
class QrCode extends PureComponent<Props, any> {

  componentDidMount() {
    this.queryData();
  }

  queryData() {
    const { dispatch } = this.props;
    dispatch({ type: 'qrcode_owner/queryInfo'}).then(() => {
      const { details } = this.props;
      this.props.onChanges([{ belongId: details.id, name: details.name, type: '1' }])
    })
  }

  render() {
    
    return (
      <>
        <p>单位名称: {this.props.details.name}</p>
        <p>单位地址: {this.props.details.address}</p>
      </>
    );
  }
}

export default QrCode;
